package org.jftstool.search.client;

import java.io.Serializable;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseTreeModel;

public class Node extends BaseTreeModel implements Serializable {
	private static final long serialVersionUID = 1L;

	
	public Node() {
		set("name", "");
		set("category", "");		
		set("amount", "");
		set("displayName", "");
	}

	public Node(String name, String category, String amount, Node[] children) {
		this(name, category, amount);
		for (int i = 0; i < children.length; i++) {
			add(children[i]);
		}
	}	
	
	
	public Node(String name, String category, String amount, List<Node> childrens) {
		this(name, category, amount);
		for (Node n : childrens) {
			add(n);
		}
	}		

	public Node(String name, String category, String amount){
		set("name", name);
		set("category", category);		
		set("amount", amount);
		set("displayName", (!amount.isEmpty() && !amount.equalsIgnoreCase("0")) ? name + " [" + amount + "]" : name);		
	}	
	
	public String getName(){
		return (String) get("name");
	}

	public String getCategory(){
		return (String) get("category");
	}	
	
	public String getAmount(){
		return (String) get("amount");
	}
	
	public String getDisplayName(){
		return (String) get("displayName");
	}
	
	public void setChildrens(List<Node> childrens){
		for (Node n : childrens) {
			add(n);
		}
	}
}